package acwing._2LanQiao._13No13;
/**
 * @Project : AlgorithmLearning
 * @Package : ACWing._2LanQiao._13No13
 * @File : Q4044.java
 * @Author : WangRuoyu
 * @Date : 2023/3/31 15:45
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Q4044 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] words = br.readLine().split(" ");
        int x = Integer.parseInt(words[0]);
        words = br.readLine().split(" ");
        int ma = Integer.parseInt(words[0]);
        String[] A = br.readLine().split(" ");
        words = br.readLine().split(" ");
        int mb = Integer.parseInt(words[0]);
        String[] B = br.readLine().split(" ");

        int m = Math.max(ma, mb);
        long[] p = new long[m];
        long[] a = new long[m];
        long[] b = new long[m];
        for (int i = 0; i < ma; ++i) {
            a[i] = Integer.parseInt(A[ma - 1 - i]);
        }
        for (int i = 0; i < mb; ++i) {
            b[i] = Integer.parseInt(B[mb - 1 - i]);
        }
        for (int i = 0; i < m; ++i) {
            p[i] = Math.max(a[i] + 1, b[i] + 1);
            p[i] = Math.max(p[i], 2);
            a[i] -= b[i];
        }
        b[0] = 1;
        final long MOD = 1000000007;
        for (int i = 1; i < m; ++i) {
            b[i] = b[i - 1] * p[i - 1];
            if (b[i] > MOD) {
                b[i] %= MOD;
            }
        }

        long res = 0;
        for (int i = 0; i < m; ++i) {
            res = (res + a[i] * b[i]) % MOD;
        }

        System.out.println(res);

    }
}

